# 通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换
from datetime import datetime, timedelta
now = datetime.now(tz=None)
print(now)
print("------")

now_str = now.strftime("%Y/%m/%d %H:%M:%S")
print(now_str)
print("------")

now_1 = datetime.strptime(now_str, "%Y/%m/%d %H:%M:%S")
print(type(now_1))
print("------")

now_2 = datetime.now(tz=None)
time_stamp = now_2.timestamp()
print(time_stamp)
print("------")

now_3 = datetime.fromtimestamp(time_stamp, tz=None)
print(now_3)
print("------")

# 封装一个函数，如果传入的是-1，输出的就是字符串时间
import datetime
def get_date():
    n = input("输入-1可以得到当前日期:")
    if n == "-1":
        t = datetime.datetime.now(tz=None)
        print(t.strftime("%Y-%m-%d"))
    else:
        print("输入错误！请重新输入！")
        get_date()
    return

get_date()